/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package o2uz;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author tomcat
 */
@Entity
@Table(name = "institute")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Institute.findAll", query = "SELECT i FROM Institute i"),
    @NamedQuery(name = "Institute.findByIdInstitute", query = "SELECT i FROM Institute i WHERE i.idInstitute = :idInstitute"),
    @NamedQuery(name = "Institute.findByName", query = "SELECT i FROM Institute i WHERE i.name = :name")})
public class Institute implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id_institute")
    private Integer idInstitute;
    @Basic(optional = false)
    @Column(name = "name")
    private String name;
    @JoinColumn(name = "fk_faculty", referencedColumnName = "id_faculty")
    @ManyToOne(optional = false)
    private Faculty fkFaculty;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "fkInstitute")
    private Collection<User> userCollection;

    public Institute() {
    }

    public Institute(Integer idInstitute) {
        this.idInstitute = idInstitute;
    }

    public Institute(Integer idInstitute, String name) {
        this.idInstitute = idInstitute;
        this.name = name;
    }

    public Integer getIdInstitute() {
        return idInstitute;
    }

    public void setIdInstitute(Integer idInstitute) {
        this.idInstitute = idInstitute;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Faculty getFkFaculty() {
        return fkFaculty;
    }

    public void setFkFaculty(Faculty fkFaculty) {
        this.fkFaculty = fkFaculty;
    }

    @XmlTransient
    public Collection<User> getUserCollection() {
        return userCollection;
    }

    public void setUserCollection(Collection<User> userCollection) {
        this.userCollection = userCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idInstitute != null ? idInstitute.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Institute)) {
            return false;
        }
        Institute other = (Institute) object;
        if ((this.idInstitute == null && other.idInstitute != null) || (this.idInstitute != null && !this.idInstitute.equals(other.idInstitute))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "o2uz.Institute[ idInstitute=" + idInstitute + " ]";
    }
    
}
